﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Reviewer.Entities.Services;
using Reviewer.Data;
using System.Web;
using Reviewer.Entities;
using System.Web.Caching;

namespace Reviewer.Business.Services
{
    internal class DistributorService : BaseService, IDistributorService
    {
        internal DistributorService() : base() { }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// Gets all.
        /// </summary>
        /// <returns></returns>
        public Distributor[] GetAll()
        {
            Distributor[] result = null;
            if (HttpContext.Current != null)
            {
                result = HttpContext.Current.Cache["DistributorService_GetAll"] as Distributor[];
            }
            if (null == result)
            {
                result = new DistributorRepository().SelectAll().ToArray();
                if (HttpContext.Current != null)
                {
                    HttpContext.Current.Cache.Add("DistributorService_GetAll", result, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 24, 0), CacheItemPriority.Normal, null);
                }
            }
            return result;
        }
    }
}
